﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using SurvivalStrategy.Modules.ActionArgs;
using SurvivalStrategy.Modules.Memory;
using SurvivalStrategy.Entities.EnitityComponents;
using SurvivalStrategy.WorldData;
using SurvivalStrategy.WorldData.ItemComponents;

namespace SurvivalStrategy.Modules.ActionModules
{
    class GetItemModule : ActionModule
    {
        public GetItemModule()
            : base()
        {
            AddFunction(new ActionModuleFunc(GetItem), new ActionModulePriority(GetItemPriority), ActionTags.Interaction); 
            // projektant modulu sam musi uzupelnic ta czesc
            // dopisuje tu swoje metody do listy z odpowiednimi tagami
        }

        private bool GetItem(ActionModuleArgs args)
        {
            int cooldown = 0;
            if(!this.SetMemoryValueInNone("ActionCooldown", new Number(cooldown))) //ustawi wartosc jezeli nie ma innej,
                cooldown = ((Number)this.GetMemoryValue("ActionCooldown")).Value;   //wczytuje stara wartosc jezeli taka istnieje

            if (cooldown > 0)
            {
                cooldown--;
                this.SetForceMemoryValue("ActionCooldown", new Number(cooldown));
                return false;
            }
            else
            {
                GetItemModuleArgs itemArgs = (GetItemModuleArgs)args;
                WorldElement element = itemArgs.Item;

                if (element.Removable)
                {
                    ItemComponent item = ((WorldDynamicElement)element).GetComponent<Eatable>();
                    if (item != null)
                    {
                        //if(GetComponent<EntityItemContainter>().AddItem(item))
                        item.ProvokeAction(this.GetEntitiy());
                        this.RemoveElement(element);
                    }
                }
                this.RemoveMemoryValue("ActionCooldown");
                return true;
            }
        }

        private int GetItemPriority()
        {
            return 0;
        }
    }
}
